<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Product_model short summary.
 *
 * Product_model description.
 *
 * @version 1.0
 * @author xianbin
 */
class Product_model extends CI_Model
{
    public $title;
    public $menuid;
    public $contents;
    public $keyword;
    public $description;
    public $imgurl;
    public $product_id;
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function add_product($productModel)
    {
        return  $this->db->insert('product',$productModel);
    }

    public function get_first_row_by_menuid($menuid)
    {
        $sql="select * from product where menuid=$menuid";
        return $this->db->query($sql)->row();
    }

    public function get_product_by_id($product_id)
    {
        $sql="select * from product where product_id=$product_id";
        return $this->db->query($sql)->row();
    }

    public function update_product($productModel)
    {
        $sql="update product set title='$productModel->title',contents='$productModel->contents',keyword='$productModel->keyword',description='$productModel->description',imgurl='$productModel->imgurl' where product_id=$productModel->product_id";
        return $this->db->query($sql);
    }

    public function del_product($product_id)
    {
        $sql="delete from product where product_id=$product_id";
        return $this->db->query($sql);
    }
}